/**
 * zoom.js - 3D object zoom function
 *
 * NMIT BIT Project - Infinity - A 3D Website using WebGL & HTML5 Technology
 * Infinity Grid Version 
 * Version: 0.1.2
 *
 * Author: William Liu <qzliuyuzou@gmail.com> <lyzdev@gmail.com>
 *
 * Required Server Version:
 *  PHP5 or higher
 *  MySQL 5 or higher
 *
 * Required Browser Version:
 *  Google Chrome 9 or higher
 *  Mozilla Firefox 4 Beta or higher
 *  *Apple Safari
 *
 * Copyright (c) 2011, William Liu All rights reserved.
 * Infinity is an open source 3D website project
 * Under Apache License 2.0
 * http://www.lyzsoft.cn
 * http://7cloud.wordpress.com
 *
 * Project Starting date: 8/5/2011
 * Update Date 1: 8/5/2011
 *
**/


var zoomLevel;
var scrollDetect=function(e)
{
	var direct=0;
	e = e || window.event;
	
	if(e.wheelDelta){
		direct = e.wheelDelta>0?1:-1;
		}
		else if(e.detail)
		{
			direct = e.detail<0?1:-1;
			}
	zoom(direct)
}

function zoom(arg)
{
	//test.focus();
    if(zoomLevel.value == "")
	{
		zoomLevel.value = 0;
		}
    var _value = parseInt(zoomLevel.value);
    arg>0?_value++:_value--;
    zoomLevel.value=_value;
    zoomLevel.select();
}
    
function addScrollListener(element, wheelHandle)
{
    if(typeof element != 'object') return;
    if(typeof wheelHandle != 'function') return;
    if(typeof arguments.callee.browser == 'undefined')
	{
        var user = navigator.userAgent;
        var b = {};
        b.opera = user.indexOf("Opera") > -1 && typeof window.opera == "object";
        b.khtml = (user.indexOf("KHTML") > -1 || user.indexOf("AppleWebKit") > -1 || user.indexOf("Konqueror") > -1) && !b.opera;
        b.ie = user.indexOf("MSIE") > -1 && !b.opera;
        b.gecko = user.indexOf("Gecko") > -1 && !b.khtml;
        arguments.callee.browser = b;
    }
    if(element == window)
        element = document;
    if(arguments.callee.browser.ie)
        element.attachEvent('onmousewheel', wheelHandle);
    else
        element.addEventListener(arguments.callee.browser.gecko ? 'DOMMouseScroll' : 'mousewheel', wheelHandle, false);
}

addScrollListener(window, zoom);